package com.enjoyor.soa.traffic.restt.tpcms.dubbo.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.enjoyor.soa.traffic.api.dto.tpcms.InfoStopRoadDto;
import com.enjoyor.soa.traffic.api.service.dubbo.tpcms.IDubboStopRoadService;
import com.enjoyor.soa.traffic.restt.tpcms.dubbo.IStopRoadConsumeService;
import com.enjoyor.soa.traffic.util.helper.GeomtryHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import oracle.spatial.geometry.JGeometry;

/**
 * 禁行线路操作
 * 
 * @author zsy 2018年4月26日
 *
 */
@Component
public class StopRoadConsumeService implements IStopRoadConsumeService {

    @Reference(version = "1.0.0", timeout = 10000)
    private IDubboStopRoadService dubboStopRoadService;

    @SuppressWarnings("rawtypes")
    @Override
    public ResultPojo getStopRoadPage(Page page) {
        return dubboStopRoadService.getStopRoadPage(page);
    }

    @Override
    public ResultPojo getStopRoadList(String stopRoadId, String stopRoadName, List<String> applyZoneIdList,
            String roadTypeId, String isUse) {
        return dubboStopRoadService.getStopRoadList(stopRoadId, stopRoadName, applyZoneIdList, roadTypeId, isUse);
    }

    @Override
    public ResultPojo insertStopRoad(InfoStopRoadDto infoStopRoad, String userName) {
        return dubboStopRoadService.insertStopRoad(infoStopRoad, userName);
    }

    @Override
    public ResultPojo editStopRoad(InfoStopRoadDto infoStopRoad, String userName) {
        return dubboStopRoadService.editStopRoad(infoStopRoad, userName);
    }

    @Override
    public ResultPojo deleteStopRoad(String stopRoadId, String userName) {
        return dubboStopRoadService.deleteStopRoad(stopRoadId, userName);
    }

    /**
     * 绘制地图区域
     */
    @Override
    public ResultPojo drawingRoadShape(InfoStopRoadDto infoStopRoad, String geom, String userName) {
        JGeometry jGeom = null;
        // 将信息字符串转换为对象
        if (!geom.equals("")) {
            jGeom = GeomtryHelper.getJTring2Geom(geom);
        }
        // 因为Json规范无法传入Dubbo.NaN,以下操作修改GsonBuilder.serializeSpecialFloatingPointValues的默认值,避免NaN报错
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.serializeSpecialFloatingPointValues();
        Gson gson = gsonBuilder.create();
        String jGeometryJson = gson.toJson(jGeom);
        JGeometry fromJson = gson.fromJson(jGeometryJson, JGeometry.class);
        // 存储地理位置信息
        infoStopRoad.setRoadGeo(fromJson);
        return dubboStopRoadService.drawingRoadShape(infoStopRoad, userName);
    }

}
